package com.hwl.statistics.controller;


import com.hwl.commonutils.result.RespBean;
import com.hwl.statistics.service.DailyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 网站统计日数据 前端控制器
 * </p>
 *
 * @author long
 * @since 2021-10-10
 */
@Api(tags = "统计分析管理")
@RestController
@RequestMapping("/admin/statistics")
public class DailyController {

    @Resource
    private DailyService dailyService;

    @ApiOperation("生成统计数据")
    @PostMapping("create/{day}")
    public RespBean register(@PathVariable String day) {
        if (dailyService.createStatisticsByDay(day)) {
            return RespBean.ok().message("数据统计成功！");
        }
        return RespBean.error().message("数据统计失败！");
    }

    @ApiOperation("统计数据")
    @GetMapping("showChart/{begin}/{end}")
    public RespBean showChart(@PathVariable String begin, @PathVariable String end) {
        return RespBean.ok().data(dailyService.getChartData(begin, end));
    }
}

